package com.utils;

import com.alibaba.fastjson.JSON;

public class Result {
    private Integer code;
    private String message;
    private Object data;

    public Result(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static String success(Object data) {
        return JSON.toJSONString(new Result(200, "success", data));
    }

    public static String fail(Integer code, String message) {
        return JSON.toJSONString(new Result(code, message, null));
    }

    public static String fail(Integer code) {
        return JSON.toJSONString(new Result(code, "fail", null));
    }
}
